package com.sbhc.httpclient.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author fyy
 * @Description
 * @Date 2020/5/20 16:35
 */
public class JSONUtil {


    public static void jsonHanler(String jsonStr){

        JSONArray jsonArray = JSONArray.parseArray(jsonStr);
        for (Object obj : jsonArray) {
            JSONObject jsonObject = JSONObject.parseObject(obj.toString());
            if(!StringUtils.isEmpty(jsonObject.get("userList").toString())){
                JSONArray userJson = JSONArray.parseArray(jsonObject.get("userList").toString());
                for (Object user : userJson) {
                    JSONObject userObj = JSONObject.parseObject(user.toString());
                    System.out.println(userObj.toString());
                    System.out.println("***************************************");
                    System.out.println("负责人：" + userObj.get("name"));
                    System.out.println("联系方式：" + userObj.get("name"));
                    System.out.println("负责人ID：" + userObj.get("name"));
                    System.out.println("工区：" + jsonObject.get("name"));
                    System.out.println("钉钉ID：" + jsonObject.get("id"));
                    System.out.println("***************************************");
                }
            }
        }


    }

    public static void main(String[] args) {
        String url = "http://miaowuyun.com:8081/api/department/getAll?departmentId=1";
        Map<String,String> param = new HashMap<String,String>();
        param.put("departmentId","1");
        Map<String,String> headers = new HashMap<String,String>();

        String jsonStr = HttpOldUtil.httpGet(url,param,headers);
        List<Map<String,String>> organizes = JSONAnalysisUtil.analysisOrganize(jsonStr);

        for (Map<String, String> organize : organizes) {
            System.out.println(organize.toString());
        }


    }

}
